// Domien Nowicki
#include "QtScaleToEffect.h"
#include "QtSprite.h"

QtScaleToEffect::QtScaleToEffect(): target(0)
{
}

QtScaleToEffect::~QtScaleToEffect()
{
}

QtScaleToEffect::QtScaleToEffect(const QtScaleToEffect& rhs): QtSingleAnimationEffect(rhs), target(rhs.target), endWidth(rhs.endWidth), startWidth(rhs.startWidth), endHeight(rhs.endHeight), startHeight(rhs.startHeight)
{

}

void QtScaleToEffect::SetTarget(QtSprite *sprite)
{
	target = sprite;
}

QtSprite* QtScaleToEffect::Target() const
{
	return target;
}

void QtScaleToEffect::Update(qreal value)
{
	if (target)
	{	
		qreal scaleWidth = startWidth + (endWidth-startWidth)*value;
		qreal scaleHeight = startHeight + (endHeight-startHeight)*value;
		target->SetScale(scaleWidth, scaleHeight);
	}
}

void QtScaleToEffect::SetEndScale(unsigned int width, unsigned int height)
{
	endWidth = width;
	endHeight = height;
}

void QtScaleToEffect::SetupAnimation()
{
	if (target)
	{
		startWidth = target->ScaleWidth();
		startHeight = target->ScaleHeight();
	}
}

QtAnimationEffect* QtScaleToEffect::Clone() const
{
	return new QtScaleToEffect(*this);
}

